//
//  XFYContrastView.m
//  MyWallet
//
//  Created by 小肥羊 on 15/8/24.
//  Copyright (c) 2015年 小肥羊. All rights reserved.
//

#import "XFYContrastView.h"

@implementation XFYContrastView
#pragma mark - 初始化
- (void)initValue
{
    self.leftCount = 0;
    self.rightCount = 0;
    self.leftView = [[UIView alloc] init];
    self.rightView = [[UIView alloc] init];
    [self.leftView setBackgroundColor:[UIColor greenColor]];
    [self.rightView setBackgroundColor:[UIColor redColor]];
    [self addSubview:self.leftView];
    [self addSubview:self.rightView];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initValue];
    }
    return self;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initValue];
    }
    return self;
}

#pragma mark - Set设置属性
- (void)setContrastWithLeft:(float)leftCount WithRight:(float)rightCount
{
    self.leftCount = leftCount;
    self.rightCount = rightCount;
    [self upViews];
}

#pragma mark - 界面显示
- (void)upViews
{
    float itemWidth = 0;
    float itemHeight = self.frame.size.height;
    if (self.leftCount!=0 || self.rightCount!=0) {
        itemWidth = self.frame.size.width/(self.leftCount + self.rightCount);
    }
    [self.leftView setFrame:(CGRect){CGPointZero, CGSizeMake(itemWidth * self.leftCount, itemHeight)}];
    [self.leftView setBackgroundColor:[UIColor greenColor]];
    [self.rightView setFrame:(CGRect){CGPointMake(self.leftView.frame.size.width, 0), CGSizeMake(itemWidth * self.rightCount, itemHeight)}];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self upViews];
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
